package com.android.clinic.app.ui.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.android.clinic.app.R;

/**
 * Created by cheng on 2018/3/16.
 */
public class ConfirmOrderDialog extends Dialog {

    public Context context;
    private TextView tvName, tvMobile, tvAddress, tvOrderInfo;
    private Display display;

    private OnCompleteClickListener onCompleteClickListener;

    public void setOnCompleteClickListener(OnCompleteClickListener onCompleteClickListener) {
        this.onCompleteClickListener = onCompleteClickListener;
    }

    public ConfirmOrderDialog(@NonNull Context context) {
        super(context, R.style.custom_dialog);
        this.context = context;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View convertView = View.inflate(context, R.layout.dialog_confirm_order_info_layout, null);

        // 设置Dialog最小宽度为屏幕宽度
        convertView.setMinimumWidth(display.getWidth() / 6 * 5);

        setContentView(convertView);

        setCanceledOnTouchOutside(false);

        tvName = (TextView) convertView.findViewById(R.id.tv_name);
        tvMobile = (TextView) convertView.findViewById(R.id.tv_mobile);
        tvAddress = (TextView) convertView.findViewById(R.id.tv_address);
        tvOrderInfo = (TextView) convertView.findViewById(R.id.tv_order_info);

        Button btnEdit = (Button) convertView.findViewById(R.id.btn_edit);
        Button btnConfirm = (Button) convertView.findViewById(R.id.btn_confirm);
        btnEdit.setOnClickListener(v -> dismiss());
        btnConfirm.setOnClickListener(v -> {
            if (null != onCompleteClickListener) {
                dismiss();
                onCompleteClickListener.onComplete();
            }
        });
    }

    public void setOrderInfo(String name, String mobile, String address, String orderPrice) {
        tvName.setText(name);
        tvMobile.setText(mobile);
        tvAddress.setText("地址：" + address);
        tvOrderInfo.setText("共1张，合计¥" + orderPrice);
    }

    public interface OnCompleteClickListener {
        void onComplete();
    }
}
